<{extends file="layout.tpl"}>

<{block name=css}>
<style type="text/css">
	.m-logoInfo-btn{ margin-top: 24px; }
	.groupTable{ margin-top: 20px; }
	.groupTable th, .groupTable td{ text-align: center; }
	#group{ text-align: right; }
</style>
<{/block}>


<{block name=content}>
<section class="m-panel-box">
	<h4>域名信息列表</h4>
	<div class="m-panel-body">
		<table class="table table-striped table-bordered table-hover groupTable">
			<thead>
				<tr>
					<th>域名</th>
					<th>序列</th>
					<th>描述</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody></tbody>
		</table>
		<div id="group"></div>
	</div>
</section>
<{/block}>

<{block name=js}>
<script type="text/javascript">
	loadDomain.firstLoad = true;
	
	loadDomain(1);
	//加载服务器组列表
	function loadDomain(page){
		ajaxObj('/Domains/getDnsList', 'post', {page, pageSize: 10}, function(obj){
			var str = '';
			$(".groupTable tbody").html('');
			if(obj.num != 0){
				obj.domainsList.map(function(data){
					str += `<tr>
										<td>${data.domain_name}</td>
										<td>${data.soa_serial}</td>
										<td>${data.domain_description}</td>
										<td>
											<a class="btn btn-xs btn-info" href="/Domains/seeDetails?id=${data.id}">详情</a>
											<button class="btn btn-xs btn-danger deleteDomin" data-id=${data.id}>删除</button>	
										</td>
									</tr>`

					if(loadDomain.firstLoad){
						loadDomain.firstLoad = false;
						layui.use(['laypage', 'layer'], function(){
						  var laypage = layui.laypage
						  ,layer = layui.layer;
						  
						  //总页数低于页码总数
						  laypage.render({
						    elem: 'group'
						    ,limit: 10
						    ,count: obj.num //数据总数	
						    ,theme: '#20A0FF'
						    ,jump: function(curr, first){
						    	!first && loadServerGroup(curr.curr);
						    }
						  });
						})
					}
				})
			}else{
				str += '<tr><td colspan="4">暂无信息</td></tr>'
			}
			$(".groupTable tbody").append(str);
		})
	}

	$('.groupTable').delegate('.deleteDomin', 'click', function(){
		var id = $(this).data('id');
		var layer2 = layer.confirm('你确定要删除此域名?', {icon: 3, title: '提示'}, function(){
			ajaxObj('/Domains/delData', 'get', {id}, function(obj){
				layer.msg(obj.msg);
				layer.close(layer2);
				loadDomain(1);
			})
		})
	})
</script>
<{/block}>